package com.cmbyc.FlinkSQL.Test

import org.apache.flink.streaming.api.scala._
import org.apache.flink.table.api.{DataTypes, Table}
import org.apache.flink.table.api.bridge.scala.{StreamTableEnvironment, tableConversions}
import org.apache.flink.table.descriptors.{FileSystem, OldCsv, Schema}



/**
 *
 * @program: com.cmbyc.FlinkSQL.Test
 * @author: YCLW058
 * @create: 2021-05-20 10:10
 * @decsription:
 *
 * */

object Demo01 {
  def main(args: Array[String]): Unit = {
    //1 env
    val env = StreamExecutionEnvironment.getExecutionEnvironment
    env.setParallelism(1)
    val tenv = StreamTableEnvironment.create(env)

    //2 source
    //文件路径
    val filepath="D:\\tool\\server\\IDEA\\code\\Java\\Flink\\Flink_scala\\data\\input\\test"
    //注册表 定义表结构
    tenv.connect(new FileSystem().path(filepath))
      .withFormat(new OldCsv)
      .withSchema(new Schema()
      .field("id",DataTypes.INT())
        .field("name",DataTypes.STRING())
        .field("age",DataTypes.INT())
      ).createTemporaryTable("inputTable")
    //3 transformation

    //4 sink
    val StudentTable: Table =tenv.from("inputTable")
    StudentTable.toAppendStream[(Int,String,Int)].print()
    //5 execute
    env.execute()

  }

}
